// ============================================================================
//
// Copyright (C) 2006-2007 Dengues
//
// Google Group: http://groups.google.com/group/dengues
// QQ Group: 24885404
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//
// ============================================================================
package org.dengues.designer.ui.process.models;

import org.dengues.core.process.CompElement;
import org.dengues.core.process.ICompProcess;
import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;

/**
 * Qiang.Zhang.Adolf@gmail.com class global comment. Detailled comment <br/>
 * 
 * $Id: Dengues.epf 1 2006-09-29 17:06:40Z qiang.zhang $
 * 
 */
public class CompConnectionTrac extends CompElement {

    private static final long serialVersionUID = 111115543332343L;

    private final CompConnection connection;

    public static String PROP_CHANGE = "CompConnectionTrac.change"; //$NON-NLS-1$

    private Point location = new Point(0, 0);

    private Dimension size = new Dimension();

    private String connectionTrac;

    /**
     * Qiang.Zhang.Adolf@gmail.com CompConnectionLabel constructor comment.
     */
    public CompConnectionTrac(CompConnection connection) {
        this.connection = connection;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.designer.ui.process.models.CompElement#getCompName()
     */
    @Override
    public String getCompName() {
        return "ConnectionTrac";
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.designer.ui.process.models.CompElement#getCompProcess()
     */
    @Override
    public ICompProcess getCompProcess() {
        return connection.getCompProcess();
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompElement#getLocation()
     */
    @Override
    public Point getLocation() {
        return this.location;
    }

    public void setLocation(Point location) {
        this.location = location;
        fireStructureChange(PROP_CHANGE, this.connectionTrac);
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.dengues.core.process.ICompElement#getSize()
     */
    @Override
    public Dimension getSize() {
        return size;
    }

    /**
     * Qiang.Zhang.Adolf@gmail.com Comment method "changeLocation".
     */
    public void changeLocation() {
        Point point = new Point();
        point.x = (connection.getSource().getLocation().x + connection.getTarget().getLocation().x) / 2;
        point.y = (connection.getSource().getLocation().y + connection.getTarget().getLocation().y) / 2;
        setLocation(point);
    }

    public String getConnectionTrac() {
        return this.connectionTrac;
    }

    public void setConnectionTrac(String connectionTrac) {
        this.connectionTrac = connectionTrac;
        fireStructureChange(PROP_CHANGE, this.connectionTrac);
    }

    public void setSize(Dimension size) {
        this.size = size;
    }

    public CompConnection getConnection() {
        return this.connection;
    }

}
